-
Notifications
You must be signed in to change notification settings - Fork 78
Reorganize Space::acquire #1381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
We rewrite the function into a more linear style and remove duplicated code of handling blocking for GC. Although this PR does not intend to change the logic of Space::acquire, it does fix some obvious bugs. - Previously if the current thread is a mutator, or GC is not enabled, the thread will attempt to poll and block for GC if it fails to get new pages from the PageResource. Now it panicks. - Previously the `on_pending_allocation` after failing to get new pages from PageResource did not include side metadata. Now it always includes side metadata.
This PR is now ready for review. This PR is a preparatory step for #1382 which we recently proposed. This PR does not change the semantics of |
The test case |
I agree that removing duplicate code is a good idea, but I’m not convinced that refactoring The original logic was structured roughly like this:
After refactoring, it becomes:
In the original impl, the cascading if/else structure made the control flow and conditions explicit -- it’s immediately clear which path you’re in and why. The new 'linear' version spreads out the conditions, so when reading later parts of the function, you need to track all preceding conditions and be aware of early returns. This makes it harder to reason about the logic. The 'do gc' part might be the only significant duplicated code here. It is reasonable to just extract it into a closure and reuse. |
The advantage of the new style is that the condition for polling, allocating, and doing GC are independent. It matches the new API proposed in #1400 (i.e. using boolean options) better. For example, the current control flow is
If we allow both polling and over-committing, the control flow will become
First of all, the
I think it is bad to mix control flow (to call Secondly, the duplicated code blocks for The new style emphasizes that the main thing Speaking of early returns, there are only two early returns in this function.
I think |
Oops I realized that the code in the error-handling trailer. |
We rewrite the function into a more linear style and remove duplicated code of handling blocking for GC.
Although we do not intend to change the logic of
Space::acquire
in this PR, we still fix some obvious bugs in the previousErr(_) => { ... }
code path.on_pending_allocation
after failing to get new pages fromPageResource
did not include side metadata. Now it always includes side metadata.